Re: [protobuf] Scoping in definitions

2016-02-25 Thread 'Feng Xiao' via Protocol Buffers
On Thu, Feb 25, 2016 at 5:57 AM, Tim Richardson  wrote:

> Hi, just wanted to check my declaration with you guys, is it possible to
> reuse the `Study` declaration in the `Denormalised`
>
You can define a field with type 'Study' without declaring it again in
'Denomalised'. Likewise, you don't need to declare TechnologyType multiple
times if they have the same definition. When declaring message fields, you
can reference any type defined anywhere in the same .proto file or in the
imported .proto files. For example:

package mypackage;

message Foo {  // Foo #1
  optional int32 value = 1;
}
message Bar {
  optional Foo foo1 = 1;  // This references the first Foo #1.
  optional Baz.Foo foo2 = 2;  // This reference the Foo #2 defined inside
Baz.
}
message Baz {
  message Foo {  // Foo #2
optional string description = 1;
  }
}


>
> package mypackage;
>
>
> message Dataset {
>   required string accession = 1;
>   required string url_self = 2;
>   optional string title = 3;
>   optional string description = 4;
>   repeated TechnologyType technology = 5;
>   optional int32 samples = 6;
>   optional string type = 7;
>   repeated StudyId studies = 8;
>
>
>   message StudyId {
> required string accession = 1;
>   }
>   message TechnologyType {
> required string type = 1;
>   }
> }
>
>
> message Study {
>   required string accession = 1;
>   required string url_self = 2;
>   optional string title = 3;
>   optional string description = 4;
>   optional string alternative_stable_id = 5;
>   repeated StudyType type = 6;
>   repeated DatasetId datasets = 7;
>
>
>   message DatasetId {
> required string accession = 1;
>   }
>   message StudyType {
> required string type = 1;
>   }
> }
>
>
> message Denormalised {
>   required string accession = 1;
>   required string url_self = 2;
>   required string title = 3;
>   required string description = 4;
>   repeated TechnologyType technology = 5;
>   optional int32 samples = 6;
>   optional string type = 7;
>   repeated Study studies = 8; // do I have to redeclare Study
>
>
>   message TechnologyType {
> required string type = 1;
>   }
> }
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Re: //:protobuf_java target not working

2016-02-25 Thread Steven Parkes
https://github.com/google/protobuf/pull/1278

On Mon, Feb 22, 2016 at 5:07 PM, Rohit Saboo  wrote:

> Hi bazel-discuss and protobuf,
>
> I am bringing in protobuf as an external bazel repository:
>
> git_repository(
> name = "protobuf_repo",
> commit = "32daf513ced8d51e8de6cc8d800cfc972c4df5d6",
> init_submodules = True,
> remote = "https://github.com/google/protobuf.git";,
> )
>
> and using the protobuf_java target as a dependency in my bazel java
> libraries. This fails generating the following message:
>
> ...
> > # @protobuf_repo//:gen_well_known_protos_java [action 'Executing
> genrule @protobuf_repo//:gen_well_known_protos_java']
>
> (cd /private/var/tmp/_bazel_rohit/a10731376421707628e091029859af4a/beam &&
> \
>
>   exec env - \
>
> PATH='' \
>
> TMPDIR=/var/folders/p2/yz_3gtqd4z9d15l2ptzcjbsmgn/T/ \
>
>   /bin/bash -c 'source
> external/bazel_tools/tools/genrule/genrule-setup.sh;
> bazel-out/host/bin/external/protobuf_repo/protoc
> --java_out=bazel-out/local_darwin-fastbuild/genfiles/external/protobuf_repo/wellknown.jar
> -Isrc external/protobuf_repo/src/google/protobuf/any.proto
> external/protobuf_repo/src/google/protobuf/api.proto
> external/protobuf_repo/src/google/protobuf/compiler/plugin.proto
> external/protobuf_repo/src/google/protobuf/descriptor.proto
> external/protobuf_repo/src/google/protobuf/duration.proto
> external/protobuf_repo/src/google/protobuf/empty.proto
> external/protobuf_repo/src/google/protobuf/field_mask.proto
> external/protobuf_repo/src/google/protobuf/source_context.proto
> external/protobuf_repo/src/google/protobuf/struct.proto
> external/protobuf_repo/src/google/protobuf/timestamp.proto
> external/protobuf_repo/src/google/protobuf/type.proto
> external/protobuf_repo/src/google/protobuf/wrappers.proto  && mv
> bazel-out/local_darwin-fastbuild/genfiles/external/protobuf_repo/wellknown.jar
> bazel-out/local_darwin-fastbuild/genfiles/external/protobuf_repo/wellknown.srcjar')
>
> ERROR: 
> /private/var/tmp/_bazel_rohit/a10731376421707628e091029859af4a/external/protobuf_repo/BUILD:461:1:
> Couldn't build file external/protobuf_repo/wellknown.srcjar: Executing
> genrule @protobuf_repo//:gen_well_known_protos_java failed: bash failed:
> error executing command /bin/bash -c ... (remaining 1 argument(s) skipped):
> com.google.devtools.build.lib.shell.BadExitStatusException: Process exited
> with status 1.
>
> src: warning: directory does not exist.
>
> external/protobuf_repo/src/google/protobuf/any.proto: File does not reside
> within any path specified using --proto_path (or -I).  You must specify a
> --proto_path which encompasses this file.  Note that the proto_path must be
> an exact prefix of the .proto file names -- protoc is too dumb to figure
> out when two paths (e.g. absolute and relative) are equivalent (it's harder
> than you think).
>
> The warning has the clue, and if I were to replace the import path (-Isrc)
> with -Iexternal/protobuf_repo/src. Is there an equivalent of bazel
> workspace_root that can be used for the cmd in this genrule in
> protobuf/BUILD?
> genrule(
> name = "gen_well_known_protos_java",
> srcs = WELL_KNOWN_PROTOS,
> outs = [
> "wellknown.srcjar",
> ],
> cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
>   " -Isrc $(SRCS) " +
>   " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
> tools = [":protoc"],
> )
>
> Thanks,
> Rohit Saboo
>
> --
> You received this message because you are subscribed to the Google Groups
> "bazel-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to bazel-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bazel-discuss/CAM01fBrV2W%2BSoTjaLkkU014LRcQzdTBMO_%2Be3xhm39x7dvEGaw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Sample for CodedInputStream in C#

2016-02-25 Thread Stephen LABBE
Hi,

I try to code a sample about protocol buffer over tcp.
I launch a TCPListener and a TCPClient.

I send with the TCP client and CodedOutputStream a message with some 
parameters.

But when I try to decode the message with CodedInputStream, I just have the 
first parameter of my message.
And the EmbeddedMessage is null

Could you explain to me how to decode the entire message ?

This is my listener code :
public static void ListenerProto(string ip, int port) {
TcpListener server = null;
try {
Console.WriteLine();

IPAddress localAddr = IPAddress.Parse(ip);

// TcpListener server = new TcpListener(port);
server = new TcpListener(localAddr, port);

// Start listening for client requests.
server.Start();

// Buffer for reading data
byte[] bytes = new byte[1];

// Enter the listening loop.
while (true) {
Console.WriteLine("Waiting for a connection... ");

// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");

// Get a stream object for reading and writing
NetworkStream stream = client.GetStream();

CodedInputStream cod = new CodedInputStream(stream);
 
var tcpMessage = TCPMessage.Parser.ParseFrom(cod);

// Shutdown and end connection
client.Close();
}
}
catch (SocketException e) {
Console.WriteLine($"SocketException: {e}");
}
finally {
// Stop listening for new clients.
server?.Stop();
}
}

This is my send code
public static void ClientProto(string ipServer, int port, TCPMessage 
message) {
try {
// Create a TcpClient.
// Note, for this client to work you need to have a 
TcpServer 
// connected to the same address as specified by the 
server, port
// combination.
TcpClient client = new TcpClient(ipServer, port);

//Create stream
var stream = client.GetStream();

//Create Coded output stream to send data over the tcp 
client
CodedOutputStream cod = new CodedOutputStream(stream);

// Send the message to the connected TcpServer. 
//message.WriteTo(stream);
var calculateSize = message.CalculateSize();

message.WriteTo(cod);

//Write message in tb
Console.WriteLine($"Sent: {message}");

// Close everything.
stream.Close();
client.Close();
}
catch (ArgumentNullException e) {
Console.WriteLine($"ArgumentNullException: {e}");
}
catch (SocketException e) {
Console.WriteLine($"SocketException: {e}");
}
}

And finaly that is my proto message (simplify):
syntax = "proto3";

message TCPMessage {
enum Type {
Add = 0;
Remove = 1;
Select = 2;
Update = 3;
}
message Parameter {
string name = 1;
string value = 2;
}
message EmbeddedMessage {
string id = 1;
Type type = 2;
repeated Parameter parameters = 3;
}
Type commande = 1;
EmbeddedMessage type = 2;
}


-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Scoping in definitions

2016-02-25 Thread Tim Richardson
Hi, just wanted to check my declaration with you guys, is it possible to 
reuse the `Study` declaration in the `Denormalised` 

package mypackage;


message Dataset {
  required string accession = 1;
  required string url_self = 2;
  optional string title = 3;
  optional string description = 4;
  repeated TechnologyType technology = 5;
  optional int32 samples = 6;
  optional string type = 7;
  repeated StudyId studies = 8;


  message StudyId {
required string accession = 1;
  }
  message TechnologyType {
required string type = 1;
  }
}


message Study {
  required string accession = 1;
  required string url_self = 2;
  optional string title = 3;
  optional string description = 4;
  optional string alternative_stable_id = 5;
  repeated StudyType type = 6;
  repeated DatasetId datasets = 7;


  message DatasetId {
required string accession = 1;
  }
  message StudyType {
required string type = 1;
  }
}


message Denormalised {
  required string accession = 1;
  required string url_self = 2;
  required string title = 3;
  required string description = 4;
  repeated TechnologyType technology = 5;
  optional int32 samples = 6;
  optional string type = 7;
  repeated Study studies = 8; // do I have to redeclare Study


  message TechnologyType {
required string type = 1;
  }
}



-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.