<commit_before>(ns flatland.protobuf.core
  (:use [flatland.protobuf.schema :only [field-schema]]
        [flatland.useful.fn :only [fix]]
        [clojure.java.io :only [input-stream output-stream]])
  (:require flatland.useful.utils)
  (:import (flatland.protobuf PersistentProtocolBufferMap PersistentProtocolBufferMap$Def PersistentProtocolBufferMap$Def$NamingStrategy Extensions)
           (com.google.protobuf GeneratedMessage CodedInputStream Descriptors$Descriptor)
           (java.io InputStream OutputStream)
           (clojure.lang Reflector)))

(defn protobuf?
  "Is the given object a PersistentProtocolBufferMap?"
  [obj]
  (instance? PersistentProtocolBufferMap obj))

(defn protodef?
  "Is the given object a PersistentProtocolBufferMap$Def?"
  [obj]
  (instance? PersistentProtocolBufferMap$Def obj))

(defn ^PersistentProtocolBufferMap$Def protodef
  "Create a protodef from a string or protobuf class."
  ([def]
     (if (or (protodef? def) (nil? def))
       def
       (protodef def PersistentProtocolBufferMap$Def/convertUnderscores)))
  ([def opts]
     (when def
       (let [{:keys [^PersistentProtocolBufferMap$Def$NamingStrategy naming-strategy
                     size-limit]
              :or {naming-strategy PersistentProtocolBufferMap$Def/convertUnderscores
                   size-limit 67108864}} opts ;; 64MiB
             ^Descriptors$Descriptor descriptor
             (if (instance? Descriptors$Descriptor def)
               def
               (Reflector/invokeStaticMethod ^Class def "getDescriptor" (to-array nil)))]
         (PersistentProtocolBufferMap$Def/create descriptor naming-strategy size-limit)))))

(defn protobuf
  "Construct a protobuf of the given type."
  ([^PersistentProtocolBufferMap$Def type]<commit_msg>Protobuf takes a map, not a naming strategy.<commit_after>(ns flatland.protobuf.core
  (:use [flatland.protobuf.schema :only [field-schema]]
        [flatland.useful.fn :only [fix]]
        [clojure.java.io :only [input-stream output-stream]])
  (:require flatland.useful.utils)
  (:import (flatland.protobuf PersistentProtocolBufferMap PersistentProtocolBufferMap$Def PersistentProtocolBufferMap$Def$NamingStrategy Extensions)
           (com.google.protobuf GeneratedMessage CodedInputStream Descriptors$Descriptor)
           (java.io InputStream OutputStream)
           (clojure.lang Reflector)))

(defn protobuf?
  "Is the given object a PersistentProtocolBufferMap?"
  [obj]
  (instance? PersistentProtocolBufferMap obj))

(defn protodef?
  "Is the given object a PersistentProtocolBufferMap$Def?"
  [obj]
  (instance? PersistentProtocolBufferMap$Def obj))

(defn ^PersistentProtocolBufferMap$Def protodef
  "Create a protodef from a string or protobuf class."
  ([def]
     (if (or (protodef? def) (nil? def))
       def
       (protodef def {})))
  ([def opts]
     (when def
       (let [{:keys [^PersistentProtocolBufferMap$Def$NamingStrategy naming-strategy
                     size-limit]
              :or {naming-strategy PersistentProtocolBufferMap$Def/convertUnderscores
                   size-limit 67108864}} opts ;; 64MiB
             ^Descriptors$Descriptor descriptor
             (if (instance? Descriptors$Descriptor def)
               def
               (Reflector/invokeStaticMethod ^Class def "getDescriptor" (to-array nil)))]
         (PersistentProtocolBufferMap$Def/create descriptor naming-strategy size-limit)))))

(defn protobuf
  "Construct a protobuf of the given type."
  ([^PersistentProtocolBufferMap$Def type]
{'fraction_non_alphanumeric': 0.0966183574879227, 'fraction_numerical': 0.005683432793407218, 'mean_word_length': 3.547803617571059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285739', 'n_tokens_mistral': 1032, 'n_tokens_neox': 997, 'n_words': 247}