github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/blobserver/protocol/protocol.go (about) 1 /* 2 Copyright 2014 The Camlistore Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package protocol contains types for Camlistore protocol types. 18 package protocol 19 20 import ( 21 "encoding/json" 22 23 "camlistore.org/pkg/blob" 24 ) 25 26 type RefAndSize struct { 27 Ref blob.Ref `json:"blobRef"` 28 Size uint32 `json:"size"` 29 } 30 31 // StatResponse is the JSON document returned from the blob batch stat 32 // handler. 33 // 34 // See doc/protocol/blob-stat-protocol.txt. 35 type StatResponse struct { 36 Stat []*RefAndSize `json:"stat"` 37 CanLongPoll bool `json:"canLongPoll"` // TODO: move this to discovery? 38 } 39 40 func (p *StatResponse) MarshalJSON() ([]byte, error) { 41 v := *p 42 if v.Stat == nil { 43 v.Stat = []*RefAndSize{} 44 } 45 return json.Marshal(v) 46 } 47 48 // UploadResponse is the JSON document returned from the blob batch 49 // upload handler. 50 // 51 // See doc/protocol/blob-upload-protocol.txt. 52 type UploadResponse struct { 53 Received []*RefAndSize `json:"received"` 54 ErrorText string `json:"errortext,omitempty"` 55 } 56 57 func (p *UploadResponse) MarshalJSON() ([]byte, error) { 58 v := *p 59 if v.Received == nil { 60 v.Received = []*RefAndSize{} 61 } 62 return json.Marshal(v) 63 }