# HG changeset patch # User telesto # Date 1418726123 -3600 # Tue Dec 16 11:35:23 2014 +0100 # Node ID 619def24a8009f37f886b201029c2e920ce67721 # Parent a6ac7c9cf6b037e662d35fcb99e25b26ceb77d89 added documentation diff --git a/cmd/hackurist/main.go b/cmd/hackurist/main.go --- a/cmd/hackurist/main.go +++ b/cmd/hackurist/main.go @@ -47,7 +47,7 @@ return err } result, err := conn.RunCommand(cmd, args) - fmt.Print(string(result)) + os.Stdout.Write(result) if err != nil { return err } diff --git a/hackurist.go b/hackurist.go --- a/hackurist.go +++ b/hackurist.go @@ -64,6 +64,9 @@ return err } +// These are representations of the dfhack RPCHandshakeHeader, defined in RemoteClient.h. +// As these values don't change they are kept as raw byte sequence +// (see header documentation for more information). var ( handshakeRequest = "DFHack?\n\x01\x00\x00\x00" handshakeResponse = "DFHack!\n\x01\x00\x00\x00" @@ -97,8 +100,13 @@ const sizeHeader = 8 -// marshaled: xx00yyyy, where x=id and y=size -// size is ignored when id = RequestQuit +// header is the equivalent of the dfhack RPCMessageHeader, defined in RemoteClient.h. +// dfhack writes the header in front of every message. +// The header is written raw to the connection, so we need to simulate this. +// +// The serialized header looks like this: "xx00yyyy", where "xx" is the header id and y the +// size of the attached message. 0 are struct padding bytes, these are ignored. +// The numbers are little endian. type header struct { id headerId size int32 @@ -134,8 +142,7 @@ } // RunCommand sends a rpc command to the server. -// It reads the response, processes it and returns the output -// ready for a text client. +// It reads the response, unmarshals it and returns the output. func (c Conn) RunCommand(cmd string, args []string) ([]byte, error) { protoCmd, err := proto.Marshal(&dfproto.CoreRunCommandRequest{Command: &cmd, Arguments: args}) if err != nil {